# def trim(s):
#     s2 = ""
#     # for i in s:
#     #     if i == " ":
#     #         continue
#     #     else:
#     #         s2 += i
#     # return s2

def trim(str):
    if (str[:1]) != " " and (str[-1:]) != " ":
        return str
    elif (str[:1]) == " ":
        return trim(str[1:])
    else:
        return trim(str[:-1])


# 测试:
if trim('hello  ') != 'hello':
    print('测试失败!')
elif trim('  hello') != 'hello':
    print('测试失败!')
elif trim('  hello  ') != 'hello':
    print('测试失败!')
elif trim('  hello  world  ') != 'hello  world':
    print('测试失败!')
elif trim('') != '':
    print('测试失败!')
elif trim('    ') != '':
    print('测试失败!')
else:
    print('测试成功!')
